/********************************************************************************/
/*										*/
/*		 Miscellaneous Memory Manipulation Routines			*/
/*			     Written by Ken Goldman				*/
/*		       IBM Thomas J. Watson Research Center			*/
/*            $Id: Memory_fp.h 1476 2019-06-10 19:32:03Z kgoldman $		*/
/*										*/
/*  Licenses and Notices							*/
/*										*/
/*  1. Copyright Licenses:							*/
/*										*/
/*  - Trusted Computing Group (TCG) grants to the user of the source code in	*/
/*    this specification (the "Source Code") a worldwide, irrevocable, 		*/
/*    nonexclusive, royalty free, copyright license to reproduce, create 	*/
/*    derivative works, distribute, display and perform the Source Code and	*/
/*    derivative works thereof, and to grant others the rights granted herein.	*/
/*										*/
/*  - The TCG grants to the user of the other parts of the specification 	*/
/*    (other than the Source Code) the rights to reproduce, distribute, 	*/
/*    display, and perform the specification solely for the purpose of 		*/
/*    developing products based on such documents.				*/
/*										*/
/*  2. Source Code Distribution Conditions:					*/
/*										*/
/*  - Redistributions of Source Code must retain the above copyright licenses, 	*/
/*    this list of conditions and the following disclaimers.			*/
/*										*/
/*  - Redistributions in binary form must reproduce the above copyright 	*/
/*    licenses, this list of conditions	and the following disclaimers in the 	*/
/*    documentation and/or other materials provided with the distribution.	*/
/*										*/
/*  3. Disclaimers:								*/
/*										*/
/*  - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF	*/
/*  LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH	*/
/*  RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES)	*/
/*  THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE.		*/
/*  Contact TCG Administration (admin@trustedcomputinggroup.org) for 		*/
/*  information on specification licensing rights available through TCG 	*/
/*  membership agreements.							*/
/*										*/
/*  - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED 	*/
/*    WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR 	*/
/*    FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR 		*/
/*    NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY 		*/
/*    OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE.		*/
/*										*/
/*  - Without limitation, TCG and its members and licensors disclaim all 	*/
/*    liability, including liability for infringement of any proprietary 	*/
/*    rights, relating to use of information in this specification and to the	*/
/*    implementation of this specification, and TCG disclaims all liability for	*/
/*    cost of procurement of substitute goods or services, lost profits, loss 	*/
/*    of use, loss of data or any incidental, consequential, direct, indirect, 	*/
/*    or special damages, whether under contract, tort, warranty or otherwise, 	*/
/*    arising in any way out of use or reliance upon this specification or any 	*/
/*    information herein.							*/
/*										*/
/*  (c) Copyright IBM Corp. and others, 2016 - 2019				*/
/*										*/
/********************************************************************************/

/*(Auto-generated)
 *  Created by TpmPrototypes; Version 3.0 July 18, 2017
 *  Date: Apr  7, 2019  Time: 06:58:58PM
 */

#ifndef _MEMORY_FP_H_
#define _MEMORY_FP_H_

//*** MemoryCopy()
// This is an alias for memmove. This is used in place of memcpy because
// some of the moves may overlap and rather than try to make sure that
// memmove is used when necessary, it is always used.
void MemoryCopy(void* dest, const void* src, int sSize);

//*** MemoryEqual()
// This function indicates if two buffers have the same values in the indicated
// number of bytes.
//  Return Type: BOOL
//      TRUE(1)         all octets are the same
//      FALSE(0)        all octets are not the same
BOOL MemoryEqual(const void*  buffer1,  // IN: compare buffer1
                 const void*  buffer2,  // IN: compare buffer2
                 unsigned int size      // IN: size of bytes being compared
);

//*** MemoryCopy2B()
// This function copies a TPM2B. This can be used when the TPM2B types are
// the same or different.
//
// This function returns the number of octets in the data buffer of the TPM2B.
LIB_EXPORT INT16 MemoryCopy2B(TPM2B*       dest,    // OUT: receiving TPM2B
                              const TPM2B* source,  // IN: source TPM2B
                              unsigned int dSize  // IN: size of the receiving buffer
);

//*** MemoryConcat2B()
// This function will concatenate the buffer contents of a TPM2B to an
// the buffer contents of another TPM2B and adjust the size accordingly
//      ('a' := ('a' | 'b')).
void MemoryConcat2B(
    TPM2B*       aInOut,   // IN/OUT: destination 2B
    TPM2B*       bIn,      // IN: second 2B
    unsigned int aMaxSize  // IN: The size of aInOut.buffer (max values for
                           //     aInOut.size)
);

//*** MemoryEqual2B()
// This function will compare two TPM2B structures. To be equal, they
// need to be the same size and the buffer contexts need to be the same
// in all octets.
//  Return Type: BOOL
//      TRUE(1)         size and buffer contents are the same
//      FALSE(0)        size or buffer contents are not the same
BOOL MemoryEqual2B(const TPM2B* aIn,  // IN: compare value
                   const TPM2B* bIn   // IN: compare value
);

//*** MemorySet()
// This function will set all the octets in the specified memory range to
// the specified octet value.
// Note: A previous version had an additional parameter (dSize) that was
// intended to make sure that the destination would not be overrun. The
// problem is that, in use, all that was happening was that the value of
// size was used for dSize so there was no benefit in the extra parameter.
void MemorySet(void* dest, int value, size_t size);

//*** MemoryPad2B()
// Function to pad a TPM2B with zeros and adjust the size.
void MemoryPad2B(TPM2B* b, UINT16 newSize);

//*** Uint16ToByteArray()
// Function to write an integer to a byte array
void Uint16ToByteArray(UINT16 i, BYTE* a);

//*** Uint32ToByteArray()
// Function to write an integer to a byte array
void Uint32ToByteArray(UINT32 i, BYTE* a);

//*** Uint64ToByteArray()
// Function to write an integer to a byte array
void Uint64ToByteArray(UINT64 i, BYTE* a);

//*** ByteArrayToUint8()
// Function to write a UINT8 to a byte array. This is included for completeness
// and to allow certain macro expansions
UINT8
ByteArrayToUint8(BYTE* a);

//*** ByteArrayToUint16()
// Function to write an integer to a byte array
UINT16
ByteArrayToUint16(BYTE* a);

//*** ByteArrayToUint32()
// Function to write an integer to a byte array
UINT32
ByteArrayToUint32(BYTE* a);

//*** ByteArrayToUint64()
// Function to write an integer to a byte array
UINT64
ByteArrayToUint64(BYTE* a);

#endif  // _MEMORY_FP_H_
